//
//  IslanOtherWrongController.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/4/11.
//  Copyright © 2016年 game. All rights reserved.
//

#import "IslanOtherWrongController.h"

@interface IslanOtherWrongController ()<UITextViewDelegate,UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UITextField *textField;

@property (nonatomic,strong) UILabel *placeHolderLabel;

@end

@implementation IslanOtherWrongController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.app.myTabBar.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;
    StatusBlack;
}
- (IBAction)backAction:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)Tijiao:(id)sender {
    
    [[Manager sharedManager]RequestWhithURL:GetFormhash AndParameter:nil AndCompletionType:^(id responseObject, DIEError *error) {
        if ([responseObject[@"status"] isEqualToString:@"SUCCESS"]) {
        
            
            NSDictionary *dic = @{
                                  @"formhash":responseObject[@"data"][@"formhash"],
                                  @"d_id":self.tid,
                                  @"comment":self.textView.text,
                                  @"phone":self.textField.text,
                                  };
            [[Manager sharedManager]ResponseWhithURL:[NSString stringWithFormat:islanOtherWoring,self.module] AndParameter:dic AndCompletionType:^(id responseObject, DIEError *error) {
                
                if (!error) {
                
                    [Manager GetHudWhithText:responseObject[@"message"] AndFatherView:self.view];
                    
                   
                    if ([responseObject[@"status"] isEqualToString:@"SUCCESS"]) {
                    
                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                            [self.navigationController popViewControllerAnimated:YES];

                        });
                    }
                    
                }else{
                    [Manager GetHudWhithText:@"提交失败" AndFatherView:self.view];
                }
                
            }];
            
        
        }else{
            [Manager GetHudWhithText:@"提交失败" AndFatherView:self.view];
        
        }
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.frame = [UIScreen mainScreen].bounds;
    self.view.backgroundColor = tabPlainBackColor;
    
    self.textView.delegate = self;
    //水印字体
    [_placeHolderLabel removeFromSuperview];
    _placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, CGRectGetWidth(_textView.frame), 30)];
    _placeHolderLabel.textColor = [UIColor lightGrayColor];
    _placeHolderLabel.font = font(SCREEN_WIDTH*0.05);
    _placeHolderLabel.userInteractionEnabled = NO;
    _placeHolderLabel.text = @"请写下您发现的问题";
    _placeHolderLabel.hidden = ![@"" isEqualToString:self.textView.text];
    [_textView addSubview:_placeHolderLabel];
    
    UITapGestureRecognizer *tap  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@ selector(tapAction)];
    [self.view addGestureRecognizer:tap];
}
-(void)tapAction{

    [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
}
#pragma mark - text view delegate
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView{
    _placeHolderLabel.hidden = ![@"" isEqualToString:textView.text];
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    if ([string isEqualToString:@"\n"]) {
        [textField resignFirstResponder];
        return NO;
    }
    return YES;

}
@end
